package com.winning.ds.role.controller;

import com.winning.ds.common.controller.BaseController;
import com.winning.ds.common.controller.CommonApi;
import com.winning.ds.common.entity.*;
import com.winning.ds.common.service.CommonApiService;
import com.winning.ds.role.entity.*;
import com.winning.ds.role.entity.*;
import com.winning.ds.role.service.SysUserService;
import com.winning.ds.common.util.*;
import com.winning.jcpt.sdk.sm4.SM4Utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/** @Author: lxd@winning.com.cn @Description: 机构用户模块 @Date: 2018-07-12 10:50:08 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

  @Autowired private SysUserService sysUserService;

  @Autowired private CommonApi commonApi;

  @Autowired private CommonApiService commonApiService;

  /**
   * 查询字典表
   *
   * @param
   * @return ResponseEntity
   */
  @RequestMapping(value = "/queryDict", method = RequestMethod.GET)
  public ResponseEntity findUserList(HttpServletRequest request) {
    List<SysSjyzymlEntity> list = sysUserService.queryZwDic();
    return ResponseEntity.ok().put("list", list);
  }

  /**
   * 查询用户列表
   *
   * @param queryParams
   * @return ResponseEntity
   */
  @RequestMapping(value = "/userlist", method = RequestMethod.POST)
  public ResponseEntity findUserList(HttpServletRequest request, @RequestBody Map queryParams) {
    PageBean page =
        (PageBean)
            ConverterUtils.map2ObjectWithoutNullValue(
                (Map<String, String>) queryParams.get("page"), PageBean.class);
    page.setOrderColumn("order by t1.mmxgsj desc");
    queryParams.put("page", page);
    queryParams.put("jgbm", (String) queryParams.get("jgbm"));

    List<SysUserEntity> list = sysUserService.queryList(queryParams);
    return PaginationResponseEntity.ok(page).put("rows", list);
  }

  /**
   * 查询医护人员列表
   *
   * @param queryParams
   * @return ResponseEntity
   */
  @RequestMapping(value = "/yhrylist", method = RequestMethod.POST)
  public ResponseEntity yhrylist(HttpServletRequest request, @RequestBody Map queryParams) {
    PageBean page =
        (PageBean)
            ConverterUtils.map2ObjectWithoutNullValue(
                (Map<String, String>) queryParams.get("page"), PageBean.class);
    page.setOrderColumn("order by t1.yljgdm desc");
    queryParams.put("page", page);
    String jgbm = (String) queryParams.get("jgbm");
    if (StringUtils.isEmpty(jgbm)) {
      queryParams.put("jgbm", getJgbm());
    }
    List<YhryxxEntity> list = sysUserService.yhryList(queryParams);
    return PaginationResponseEntity.ok(page).put("rows", list);
  }

  /**
   * 根据注册流水号查询用户信息
   *
   * @param zclsh
   * @return ResponseEntity
   */
  @RequestMapping(value = "/queryUser/{zclsh}", method = RequestMethod.GET)
  public ResponseEntity queryUserObject(HttpServletRequest request, @PathVariable String zclsh) {
    CommonJgUserEntity us = sysUserService.queryUserObject(zclsh);
    return ResponseEntity.ok().put("us", us);
  }

  /**
   * 根据账号查询用户信息
   *
   * @param dldm
   * @return ResponseEntity
   */
  @RequestMapping(value = "/queryUserBydldm/{dldm}", method = RequestMethod.GET)
  public ResponseEntity queryUserObjectBydldm(
      HttpServletRequest request, @PathVariable String dldm) {
    SysUserEntity us = sysUserService.selectByUserName(dldm);
    return ResponseEntity.ok().put("isExit", us == null ? "NO" : "YES");
  }

  /**
   * 保存
   *
   * @param user
   * @return ResponseEntity
   */
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  public ResponseEntity save(HttpServletRequest request, @RequestBody SysUserEntity user) {

    String dldm = user.getDldm();
    SysUserEntity us = sysUserService.selectByUserName(dldm);
    if (us != null) {
      return ResponseEntity.error(500, "登录账号已存在");
    }

    user.setZclsh(UUIDUtils.getUUID());
    user.setQyzt("Y");
    user.setRybm(user.getZclsh());
    user.setJlzt("0");
    user.setMmxgsj(new Date());

    String zwbm = user.getZwbm();
    if (zwbm != null && !"".equals(zwbm)) {
      String zwmc = commonApiService.sysSjyzymlObject("GB/T 8561-2001", zwbm).getZmc();
      user.setZwmc(zwmc);
    }

    String sbcs = user.getSbcs(); // 失败次数，前台传值 正常：1 锁定：0
    if ("1".equals(sbcs)) {
      user.setSbcs("0");
    } else {
      SysQjcsEntity lecEntity = commonApiService.queryQjcs("login_error_count");
      if (lecEntity != null && StringUtils.isNotEmpty(lecEntity.getCsz())) {
        user.setSbcs(lecEntity.getCsz());
      }
      user.setSdsj(new Date());
    }

    String tempKey = user.getTempKey();
    String password = user.getPassword();
    SM4Utils sm4Utils = new SM4Utils();
    String mm = sm4Utils.decryptData_CBC(password, tempKey); // 先解密非对称的密码
    user.setDlmm(mm); // 保存密码（明文）
    password = sm4Utils.encryptData_CBC(mm); // 采用对称的加密
    user.setPassword(password);

    ResponseEntity responseEntity = validatePassword(user); // 校验密码复杂度
    String code = responseEntity.get("code").toString();
    if (!"200".equals(code)) {
      return responseEntity;
    }
    sysUserService.save(user);
    return ResponseEntity.ok();
  }

  /**
   * 更新
   *
   * @param user
   * @return ResponseEntity
   */
  @RequestMapping(value = "/update", method = RequestMethod.POST)
  public ResponseEntity update(HttpServletRequest request, @RequestBody SysUserEntity user) {
    // ValidatorUtils.validateEntity(user);
    String dldm = user.getDldm();
    SysUserEntity us = sysUserService.selectByUserName(dldm);
    // 登录账号相同且不是同一个人且时
    if (us != null && !us.getZclsh().equals(user.getZclsh())) {
      return ResponseEntity.error(500, "登录账号已存在");
    }

    SysUserEntity ysUserEntity = sysUserService.selectByUserName(user.getDldm());
    String ysmm = ysUserEntity.getPassword();
    SM4Utils sm4Utils = new SM4Utils();
    String password = user.getPassword();
    String tempKey = user.getTempKey();

    // tempKey为空时说明页面未修改密码，密码是和数据库中相同，属于对称加密的密码
    // 不为空说明密码新增或者修改，前台进行非对称加密
    if (StringUtils.isNotEmpty(tempKey)) {
      String mm = sm4Utils.decryptData_CBC(password, tempKey); // 先解密非对称的密码
      user.setDlmm(mm); // 保存密码（明文）
      user.setYsmm(ysUserEntity.getDlmm());
      password = sm4Utils.encryptData_CBC(mm); // 采用对称的加密
    }
    user.setPassword(password); // 保存密码（对称加密）
    // 修改为和原先相同的密码，密码更新时间不更新
    if (StringUtils.isNotEmpty(ysmm) && !ysmm.equals(password)) {
      user.setMmxgsj(new Date());
    }

    ResponseEntity responseEntity = validatePassword(user); // 校验密码复杂度和有效期
    String code = responseEntity.get("code").toString();
    if (!"200".equals(code)) {
      return responseEntity;
    }

    String zwbm = user.getZwbm(); // 职位编码
    if (StringUtils.isNotEmpty(zwbm)) {
      String zwmc = commonApiService.sysSjyzymlObject("GB/T 8561-2001", zwbm).getZmc();
      user.setZwmc(zwmc);
    }

    String qyzt = user.getQyzt(); // 锁定状态，前台传值 正常：Y 锁定：N
    if ("Y".equals(qyzt)) {
      user.setSbcs("0");
    } else {
      SysQjcsEntity lecEntity = commonApiService.queryQjcs("login_error_count");
      if (lecEntity != null && StringUtils.isNotEmpty(lecEntity.getCsz())) {
        String login_error_count = lecEntity.getCsz();
        user.setSbcs(login_error_count);
      }
      user.setSdsj(new Date());
    }

    sysUserService.update(user);
    return ResponseEntity.ok();
  }

  public ResponseEntity validatePassword(SysUserEntity user) {

    // 非超级管理员时，根据是否需要检验密码强度和密码有效期
    if (user != null && !"超级管理员".equals(user.getRylx()) && !"2".equals(user.getRylx())) {
      SysQjcsEntity YXQqjcsEntity = commonApiService.queryQjcs("plat_MMYYQ");

      String yyq = null;

      // 数字字母符合两种以上组合
      // ^(?![a-zA-z]+$)(?![0-9]+$)(?![!@#$%^&*]+$)[a-zA-Z0-9!@#$%^&*]+$
      // 八位以上数字字母符合两种以上组合
      // ^(?![a-zA-z]+$)(?![0-9]+$)(?![!@#$%^&*]+$)[a-zA-Z0-9!@#$%^&*]{8,}$
      if (YXQqjcsEntity != null) {
        yyq = YXQqjcsEntity.getCsz();
      }
      if (yyq != null && !yyq.equals("null") && !yyq.equals("") && !yyq.equals("0")) {
        if (user.getMmxgsj() == null) {
          return ResponseEntity.error("登录密码已过期");
        } else {
          Date dateBegin = user.getMmxgsj();
          Date dateEnd = new Date();
          long dateDiff = dateEnd.getTime() - dateBegin.getTime(); // 时间差的毫秒数
          double dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); // 计算出相差天数
          if (dayDiff > Integer.parseInt(yyq)) {
            return ResponseEntity.error("登录密码已过期");
          }
        }
      }

      // 优先校验默认密码校验规则
      SysQjcsEntity mrmmjygz = commonApiService.queryQjcs("plat_MRMMJYGZ");
      SM4Utils sm4Utils = new SM4Utils();
      String password = sm4Utils.decryptData_CBC(user.getPassword());
      if (mrmmjygz != null
          && StringUtils.isNotEmpty(mrmmjygz.getCsz())
          && !"0".equals(mrmmjygz.getCsz())) {
        String csz = StringUtils.trimToEmpty(mrmmjygz.getCsz());
        List<Map<String, Object>> optionList = sysUserService.getOptionList(mrmmjygz.getQzsql());
        if (!password.matches(csz)) {
          String msg = "密码复杂度不符合规则:";
          for (Map<String, Object> map : optionList) {
            if (csz.equals(map.get("XMDM"))) {
              msg = msg + map.get("XMMC");
            }
          }
          return ResponseEntity.error(msg);
        }
      } else {
        // 若未设置默认密码规则，则校验自定义密码规则
        String reg = null;
        SysQjcsEntity JYGZqjcsEntity = commonApiService.queryQjcs("plat_MMJYGZ");
        if (JYGZqjcsEntity != null && StringUtils.isNotEmpty(JYGZqjcsEntity.getCsz())) {
          reg = JYGZqjcsEntity.getCsz().trim();
        }
        if (reg != null && !reg.equals("null") && !reg.equals("")) {

          if (!password.matches(reg)) {
            return ResponseEntity.error("登录密码不符合校验规则");
          }
        }
      }
    }

    return ResponseEntity.ok();
  }
  /**
   * 删除角色
   *
   * @param zclsh
   * @return
   */
  @RequestMapping(value = "/delUser/{zclsh}", method = RequestMethod.DELETE)
  public ResponseEntity delRoleList(HttpServletRequest request, @PathVariable String zclsh) {
    sysUserService.deleteUser(zclsh);
    return ResponseEntity.ok();
  }

  /**
   * 查询科室信息
   *
   * @param jgdm
   * @return ResponseEntity
   */
  @RequestMapping(value = "/queryKsxx/{jgdm}", method = RequestMethod.GET)
  public ResponseEntity queryKsxx(HttpServletRequest request, @PathVariable String jgdm) {
    List<SysSjyzymlEntity> list = sysUserService.queryKsxx(jgdm);
    return ResponseEntity.ok().put("list", list);
  }

  /**
   * 保存用户角色信息
   *
   * @param request
   * @param userRole
   * @return
   */
  @RequestMapping(value = "/saveUserRole", method = RequestMethod.POST)
  public ResponseEntity saveUserRole(HttpServletRequest request, @RequestBody Map userRole) {
    List czry = (List) userRole.get("czry");
    List jsxx = (List) userRole.get("jsxx");
    saveUserRoleList(czry, jsxx);
    return ResponseEntity.ok();
  }

  /**
   * 保存用户角色信息
   *
   * @param czry
   * @param jsxx
   */
  private void saveUserRoleList(List<Map> czry, List<Map> jsxx) {
    sysUserService.saveUserRoleList(czry, jsxx);
  }

  /**
   * 查询用户角色信息
   *
   * @param zclsh
   * @return ResponseEntity
   */
  @RequestMapping(value = "/getUserRole/{zclsh}", method = RequestMethod.GET)
  public ResponseEntity getUserRole(HttpServletRequest request, @PathVariable String zclsh) {
    List<SysUserEntity> list = sysUserService.getUserRole(zclsh);
    return ResponseEntity.ok().put("list", list);
  }

  /**
   * 批量从医护人员表中导入到用户信息表，并保存角色关系
   *
   * @param request
   * @param userRole
   * @return
   */
  @RequestMapping(value = "/pldrYh", method = RequestMethod.POST)
  public ResponseEntity pldrYh(HttpServletRequest request, @RequestBody Map userRole) {
    List<SysUserEntity> czryList = new ArrayList<SysUserEntity>();
    List<Map> yhry = (List) userRole.get("yhry"); // 医护人员列表
    // 为了调用保存角色方法，重新封装一个map
    List<Map> czry = new ArrayList<Map>();
    Map mp = new HashMap();

    if (yhry != null && yhry.size() > 0) {
      for (int i = 0; i < yhry.size(); i++) {
        SysUserEntity us = new SysUserEntity();
        String zclsh = UUIDUtils.getUUID();
        us.setJgbm(yhry.get(i).get("yljgdm").toString());
        us.setZclsh(zclsh);
        String gh = yhry.get(i).get("gh").toString();
        gh = getdldm(gh);
        us.setDldm(gh);
        // 存入明文密码
        us.setDlmm(yhry.get(i).get("gh").toString());
        // 存入密文密码
        SM4Utils sm4Utils = new SM4Utils();
        String password = sm4Utils.encryptData_CBC(yhry.get(i).get("gh").toString());
        us.setPassword(password);

        us.setRybm(yhry.get(i).get("zgbm").toString());
        us.setRyxm(yhry.get(i).get("xm").toString());
        us.setRygh(yhry.get(i).get("gh").toString());
        us.setXb(yhry.get(i).get("xbdm") == null ? null : yhry.get(i).get("xbdm").toString());
        us.setCsrq(yhry.get(i).get("csrq") == null ? null : yhry.get(i).get("csrq").toString());
        us.setQyzt("Y");
        us.setJlzt("0");
        us.setRylx("0"); // 默认为 0 普通用户
        us.setDhhm(Optional.ofNullable(yhry.get(i).get("dhhm")).orElse("").toString());
        us.setZc(Optional.ofNullable(yhry.get(i).get("zcdm")).orElse("").toString());
        us.setKsbm(Optional.ofNullable(yhry.get(i).get("sszxksdm")).orElse("").toString());
        us.setMmxgsj(new Date());
        us.setSfzh(Optional.ofNullable(yhry.get(i).get("sfbshm")).orElse("").toString());
        us.setDhhm(Optional.ofNullable(yhry.get(i).get("sjhm1")).orElse("").toString());
        czryList.add(us);
        mp.put("zclsh", zclsh);
        mp.put("jgbm", yhry.get(i).get("yljgdm").toString());
        czry.add(mp);
      }
      // 批量新增用户信息
      sysUserService.pldrYh(czryList);

      // 保存角色信息
      // List<Map> jsxx = (List) userRole.get("jsxx");
      // saveUserRoleList(czry, jsxx);
    }

    return ResponseEntity.ok();
  }

  /**
   * 根据规则生成登录代码
   *
   * @param dldm 登录代码
   * @return 登录代码
   */
  private String getdldm(String dldm) {
    String gh = sysUserService.getMaxDldm(dldm);
    if (StringUtils.isEmpty(gh)) {
      return dldm;
    }
    char endChar = gh.charAt(gh.length() - 1);
    if (Character.isDigit(endChar)) {
      gh = gh + "a";
    } else {
      char newEndChar = (char) (endChar + 1);
      System.out.println(newEndChar);
      gh = gh.replace(endChar, newEndChar);
    }
    return gh;
  }

  /**
   * 查询用户已开通权限信息(菜单)
   *
   * @param zclsh
   * @return ResponseEntity
   */
  @RequestMapping(value = "/getQxList/{zclsh}", method = RequestMethod.GET)
  public ResponseEntity getQxList(HttpServletRequest request, @PathVariable String zclsh) {
    List<MenuTreeEntity> list = sysUserService.getQxList(zclsh);
    MenuTreeUtil mt = new MenuTreeUtil();
    List<Object> muTreeList = mt.menuTreeList(list);
    return ResponseEntity.ok().put("menuTreeList", muTreeList);
  }

  /**
   * 查询当前用户所属机构已开通权限菜单
   *
   * @return ResponseEntity
   */
  @RequestMapping(value = "/getMenuByJgbm", method = RequestMethod.GET)
  public ResponseEntity getMenuByJgbm(HttpServletRequest request) {
    String jgbm = getJgbm();
    List<MenuTreeEntity> list = sysUserService.getMenuByJgbm(jgbm);
    MenuTreeUtil mt = new MenuTreeUtil();
    List<Object> muTreeList = mt.menuTreeList(list);
    return ResponseEntity.ok().put("menuTreeList", muTreeList);
  }

  /**
   * 查询权限用户列表
   *
   * @param queryParams
   * @return ResponseEntity
   */
  @RequestMapping(value = "/queryQxyhList", method = RequestMethod.POST)
  public ResponseEntity queryQxyhList(HttpServletRequest request, @RequestParam Map queryParams) {
    String jgbm = getJgbm();
    queryParams.put("jgbm", jgbm);
    List<SysUserEntity> list = sysUserService.queryQxyhList(queryParams);
    UserTreeUtil mt = new UserTreeUtil();
    List<Object> muTreeList = mt.userTreeList(list);
    return ResponseEntity.ok().put("list", muTreeList);
  }

  /** synchronizeUserInfo operateID 操作码 userIdCode 待同步的机构信息 userType 备用 根据业务实际处理情况返回 true 或 false */
  @RequestMapping(value = "/synchronizeUserInfo")
  @ResponseBody
  public void synchronizeUserInfo(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    log.info(
        "UAMS参数operateID： "
            + request.getParameter("operateID")
            + "userIdCode："
            + request.getParameter("userIdCode"));
    if (request.getParameter("operateID") != null) {
      int operateID = Integer.parseInt(request.getParameter("operateID"));
      String userIdCode = request.getParameter("userIdCode");
      //            String userType = request.getParameter("userType");
      switch (operateID) {
        case 11:
          { // 增加、修改、授权用户
            SysQjcsEntity lecEntity = commonApiService.queryQjcs("bj_uams_address");
            SysQjcsEntity lecEntity1 = commonApiService.queryQjcs("bj_uams_authId");
            SysQjcsEntity lecEntity2 = commonApiService.queryQjcs("bj_uams_jgbm");
            String address = "";
            String authId = "";
            String jgbm = "";
            if (lecEntity != null) {
              address = lecEntity.getCsz();
            }
            if (lecEntity1 != null) {
              authId = lecEntity1.getCsz();
            }
            if (lecEntity2 != null) {
              jgbm = lecEntity2.getCsz();
            }
            Map map = new HashMap();

            StringBuilder requestUrl = new StringBuilder();
            requestUrl.append(address);
            requestUrl.append("/QueryUserInfoDetail?userIdCode=");
            requestUrl.append(userIdCode);
            requestUrl.append("&authId=");
            requestUrl.append(authId);
            log.info("UAMS地址:" + requestUrl);
            RequestProcessor requestProcessor =
                new RequestProcessor(map, requestUrl.toString(), null).invoke();
            if (requestProcessor.isFailed()) {
              log.error("向北京UAMS系统请求失败！");
            }
            String result = requestProcessor.getResult();
            log.info("UAMS返回result:" + result + "====");
            Map requestMap = new TransJsonStringToMap().TransMap(result);
            int status = Integer.parseInt(requestMap.get("status").toString());
            Map info = (Map) requestMap.get("info");
            if (status == 0) {
              log.info("UAMS用户信息:" + info.toString());
              String userName = (String) requestMap.get("userName"); // 用户姓名
              String userEmail = (String) requestMap.get("userEmail"); // 用户EMAIL
              String userPhone = (String) requestMap.get("userPhone"); // 用户手机号
              String userIdType = (String) requestMap.get("userIdType"); // 证件类型
              String userIdcardNum = (String) requestMap.get("userIdcardNum"); // 证件号码
              String sfzh = "";
              if ("SF".equals(userIdType)) {
                sfzh = userIdcardNum;
              }
              // 根据用户唯一标识查询用户信息
              SysUserEntity sysUserEntity = sysUserService.queryUserEntity(userIdCode);
              if (sysUserEntity != null) { // 修改
                // sysUserEntity.setJgbm(jgbm);
                sysUserEntity.setRyxm(userName);
                sysUserEntity.setSfzh(sfzh);
                sysUserEntity.setDhhm(userPhone);
                sysUserService.update(sysUserEntity);
              } else { // 新增
                SysUserEntity userEntity = new SysUserEntity();
                String password = "1"; // 默认密码为1
                SM4Utils sm4Utils = new SM4Utils();
                userEntity.setDlmm(password); // 保存密码（明文）
                password = sm4Utils.encryptData_CBC(password); // 采用对称的加密
                userEntity.setPassword(password);
                userEntity.setJgbm(jgbm);
                userEntity.setZclsh(userIdCode);
                userEntity.setRybm(userIdCode);
                userEntity.setDldm("bj1111");
                userEntity.setQyzt("Y");
                userEntity.setRyxm(userName);
                userEntity.setSfzh(sfzh);
                userEntity.setDhhm(userPhone);
                userEntity.setJlzt("0");
                userEntity.setMmxgsj(new Date());
                sysUserService.save(userEntity);
              }
              response.getOutputStream().write("true".getBytes());
            } else {
              log.error("UAMS请求错误信息:" + info.toString());
              response.getOutputStream().write("false".getBytes());
            }
            break;
          }
        case 13:
          { // 删除用户  ，然后返回结果 true 或 false
            log.info("UAMS删除：" + "operateID:" + operateID + " 删除用户：" + userIdCode);
            sysUserService.deleteUser(userIdCode);
            response.getOutputStream().write("true".getBytes());
            break;
          }
        case 51:
          { // 解除用户权限  ，然后返回结果 true 或 false
            log.info("UAMS删除：" + "operateID:" + operateID + " 删除用户：" + userIdCode);
            sysUserService.deleteUser(userIdCode);
            response.getOutputStream().write("true".getBytes());
            break;
          }
        default:
          {
            response.getOutputStream().write("true".getBytes());
            break;
          }
      }
    } else {
      // operateID 为空
      log.info("UAMS请求：operateID 为空");
      response.getOutputStream().write("false".getBytes());
    }
  }
  /** 北京对接国家平台获取第三方目标系统中“账号”等对象全部属性信息 */
  @RequestMapping("/SchemaService")
  public BjGjptSchemaResponseEntity schemaService(
      @RequestBody BjGjptUserRequestEntity bjGjptUserRequestEntity) {

    return sysUserService.schemaService(bjGjptUserRequestEntity);
  }
  /** 北京对接国家平台应用系统的账号创建方法 */
  @RequestMapping("/UserCreateService")
  public BjGjptUserResponseEntity userCreateService(
      @RequestBody BjGjptUserRequestEntity bjGjptUserRequestEntity) {

    return sysUserService.userCreateService(bjGjptUserRequestEntity);
  }
  /** 北京对接国家平台应用系统的账号修改方法 */
  @RequestMapping("/UserUpdateService")
  public BjGjptUserResponseEntity userUpdateService(
      @RequestBody BjGjptUserRequestEntity bjGjptUserRequestEntity) {
    return sysUserService.userUpdateService(bjGjptUserRequestEntity);
  }
  /** 北京对接国家平台应用系统的账号删除方法。 */
  @RequestMapping("/UserDeleteService")
  public BjGjptUserResponseEntity userDeleteService(
      @RequestBody BjGjptUserRequestEntity bjGjptUserRequestEntity) {
    return sysUserService.userDeleteService(bjGjptUserRequestEntity);
  }

  /**
   * 查询用户映射列表
   *
   * @param queryParams
   * @return ResponseEntity
   */
  @RequestMapping(value = "/usermappinglist", method = RequestMethod.POST)
  public ResponseEntity queryUserMappingList(
      HttpServletRequest request, @RequestBody Map queryParams) {
    PageBean page =
        (PageBean)
            ConverterUtils.map2ObjectWithoutNullValue(
                (Map<String, String>) queryParams.get("page"), PageBean.class);
    page.setOrderColumn("order by t1.inputtime desc");
    queryParams.put("page", page);

    List<PtLoginsEntity> list = sysUserService.queryUserMappingList(queryParams);
    return PaginationResponseEntity.ok(page).put("rows", list);
  }

  /**
   * 保存用户映射关系
   *
   * @param queryParams
   * @return ResponseEntity
   */
  @RequestMapping(value = "/saveUserMapping", method = RequestMethod.POST)
  public ResponseEntity saveUserMapping(HttpServletRequest request, @RequestBody Map queryParams) {
    queryParams.put("czry", getUser().getDldm());
    sysUserService.saveUserMapping(queryParams);
    return ResponseEntity.ok();
  }

  /**
   * 删除用户映射关系
   *
   * @param queryParams
   * @return ResponseEntity
   */
  @RequestMapping(value = "/delUserMapping", method = RequestMethod.POST)
  public ResponseEntity delUserMapping(HttpServletRequest request, @RequestBody Map queryParams) {
    sysUserService.delUserMapping(queryParams);
    return ResponseEntity.ok();
  }
}
